﻿function ClientAddHtml() {
    belongSite = document.getElementById("drpSelectSiteForHtml").options[document.getElementById("drpSelectSiteForHtml").selectedIndex].value;
    Url = Portal.CMS.Html.GetAddNewUrl(belongSite).value;
    window.open(Url, '_blank');
}

function ClientSaveAddHtml() {
    belongSite = document.getElementById("txtBelongSite").value;
    language = document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    Alias = document.getElementById("txtAlias").value;
    Subject = document.getElementById("txtSubject").value;
    var instanceName = "ctl04";
    var oEditor = FCKeditorAPI.GetInstance(instanceName);
    bodyText = oEditor.GetXHTML(true);
    value = Portal.CMS.AddHtml.ServerSideAddHtml(belongSite, language, Alias, Subject, bodyText).value;
    if (value.indexOf("ERROR") != -1) {
        alert(value);
        return;
    }
    window.close();
}

function ClientSaveHtml(HtmlId) {
    language = document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    Alias = document.getElementById("txtAlias").value;
    Subject = document.getElementById("txtSubject").value;
    if (FCKeditorAPI == null) {

        alert(Portal.CMS.UpdateHtml.GetLoadDataMsg().value);
        return;
    }
    var instanceName = "ctl04";
    var oEditor = FCKeditorAPI.GetInstance(instanceName);

    if (oEditor == null) {
        alert(Portal.CMS.UpdateHtml.GetLoadDataMsg().value);
        return;
    }
    bodyText = oEditor.GetXHTML(true);
    value = Portal.CMS.UpdateHtml.ServerSideHtml(language, HtmlId, Alias, Subject, bodyText).value;
    if (value.indexOf("ERROR") != -1) {
        alert(value);
        return;
    }
    retValue = Portal.CMS.UpdateHtml.GetInfoSaveMsg(language).value;
    alert(retValue);
    window.close();
}

function RunFilter() {
    document.getElementById("divProcessing").innerHTML = Portal.CMS.Html.GetProcessingText().value;
    setTimeout("RealRunFilter()", 10);
}


function RealRunFilter() {
    WorkflowStatusIndex = document.getElementById("divSelectWorkflowStatus").selectedIndex;
    WorkflowStatus = "";
    if (WorkflowStatusIndex != -1) {
        WorkflowStatus = document.getElementById("divSelectWorkflowStatus").options[WorkflowStatusIndex].value;
    }

    belongSite = document.getElementById("drpSelectSiteForHtml").options[document.getElementById("drpSelectSiteForHtml").selectedIndex].value;
    PageIndex = document.getElementById("divSelectPage").selectedIndex;
    if (PageIndex < 0) PageIndex = 0;
    value = Portal.CMS.Html.GetHtml(belongSite, WorkflowStatus, PageIndex).value;
    if (value.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(value);
        return;
    }
    document.getElementById("divProcessing").innerHTML = "";
    document.getElementById("divHtmlContent").innerHTML = value;
}


function ClientDeleteHtml(HtmlId) {
    if (confirm(Portal.CMS.Html.GetConfirmMsg().value) == false) {
        return;
    }
    value = Portal.CMS.Html.ServerSideDeleteHtml(HtmlId).value;
    if (value.indexOf("ERROR") != -1) {
        alert(value);
        return;
    }
    alert(Portal.CMS.Html.GetDeleteOkMsg().value);
    //    WorkflowStatusIndex=document.getElementById("divSelectWorkflowStatus").selectedIndex;
    //    WorkflowStatus=document.getElementById("divSelectWorkflowStatus").options[WorkflowStatusIndex].value;
    //    PageIndex=document.getElementById("divSelectPage").selectedIndex;
    //    value = Portal.CMS.Html.GetHtml(WorkflowStatus, PageIndex).value;
    //    if (value.indexOf("ERROR") != -1) {
    //        alert(value);
    //        return;
    //    }
    //    alert(value);
    RunFilter();
    //document.getElementById("divHtmlContent").innerHTML=value;
}

function ShowUpdateHtmlForm(HtmlId) {
    Url = Portal.CMS.Html.GetUpdateHtmlUrl(HtmlId).value;
    window.open(Url, '_blank');

    //    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 840px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    //    WorkflowStatusIndex=document.getElementById("divSelectWorkflowStatus").selectedIndex;
    //    WorkflowStatus=document.getElementById("divSelectWorkflowStatus").options[WorkflowStatusIndex].value;
    //    PageIndex=document.getElementById("divSelectPage").selectedIndex;
    // 
    //    value=Portal.CMS.Html.GetHtml(WorkflowStatus,PageIndex).value;
    //    if(value.indexOf("ERROR")==-1)
    //    {
    //        document.getElementById("divHtmlContent").innerHTML=value;
    //    }
    //    else
    //    {
    //        alert(value);
    //    }
}


function DetectHtmlBody(HtmlId) {
    language = document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    retValue = Portal.CMS.UpdateHtml.GetSubject(language, HtmlId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    document.getElementById("txtSubject").value = retValue;

    var instanceName = "ctl02";
    var oEditor = FCKeditorAPI.GetInstance(instanceName);
    retValue = Portal.CMS.UpdateHtml.GetBody(language, HtmlId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    oEditor.SetHTML(retValue);

}


function ClientPublishingHtml(HtmlId) {
    if (confirm(Portal.CMS.Html.GetConfirmPublishingMsg().value) == false) {
        return;
    }
    retValue = Portal.CMS.Html.ServerSidePublishing(HtmlId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}




function ClientUnPublishingHtml(HtmlId) {
    if (confirm(Portal.CMS.Html.GetConfirmUnPublishingMsg().value) == false) {
        return;
    }
    retValue = Portal.CMS.Html.ServerSideUnPublishing(HtmlId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}

function ClientSyncHtml(HtmlId) {
    if (confirm(Portal.CMS.Html.GetConfirmSyncAllMsg().value) == false) {
        return;
    }
    document.getElementById("divProcessing").innerHTML = Portal.CMS.Html.GetProcessingText().value;
    setTimeout("RealClientSyncHtml('" + HtmlId + "')", 10);
}



function RealClientSyncHtml(HtmlId) {
    retValue = Portal.CMS.Html.ServerSideSyncToServer(HtmlId).value;
    document.getElementById("divProcessing").innerHTML = "";
    alert(retValue);
}